package managesystem;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import javax.persistence.Id;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import tracksystem.Activity;
import controlsystem.Course;

//TODO:Lijst van buddies, activities en courses aanmaken en persistent maken in objectify

public class Student implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id public Long id;
	
	private String username;
	
	private String fname;
	
	private String lname;
	
	private String email;
	
	private String password;
	
	private List<Key<Course>> courseKeys = new ArrayList<Key<Course>>();
	private List<Key<Student>> buddyKeys = new ArrayList<Key<Student>>();
	private List<Key<Activity>> activityKeys =  new ArrayList<Key<Activity>>();

    @SuppressWarnings("unused")
	private Student() {}

	public Student(String fn, String ln, String email, String un, String pw){
		
		this.setFname(fn);
		this.setLname(ln);
		this.setEmail(email);
		this.setUsername(un);
		this.setPassword(pw);
		
		
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	/**
	 * @return the fname
	 */
	public String getFname() {
		return fname;
	}

	/**
	 * @param fname the fname to set
	 */
	public void setFname(String fname) {
		this.fname = fname;
	}

	/**
	 * @return the lname
	 */
	public String getLname() {
		return lname;
	}

	/**
	 * @param lname the lname to set
	 */
	public void setLname(String lname) {
		this.lname = lname;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return the courseKeys
	 */
	public Collection<Course> getCourses() {
		Objectify ofy = ObjectifyService.begin();
		Map<Key<Course>,Course> courses = ofy.get(courseKeys);
		
		return courses.values();
	}

	/**
	 * @param courseKeys the courseKeys to set
	 */
	public void addCourse(Course c) {
		System.out.println(c.getId());
		courseKeys.add(new Key<Course>(Course.class, c.getId()));
	}

	/**
	 * @return the buddieKeys
	 */
	public Collection<Student> getBuddies() {
		Objectify ofy = ObjectifyService.begin();
		Map<Key<Student>,Student> buddies = ofy.get(buddyKeys);
		
		return buddies.values();
		
	}

	/**
	 * @param buddieKeys the buddieKeys to set
	 */
	public void addBuddy(Student s) {
		buddyKeys.add(new Key<Student>(Student.class, s.id));
	}

	/**
	 * @return the activityKeys
	 */
	public Collection<Activity> getActivities() {
		Objectify ofy = ObjectifyService.begin();
		Map<Key<Activity>,Activity> activities = ofy.get(activityKeys);
		
		return activities.values();
	}

	/**
	 * @param activityKeys the activityKeys to set
	 */
	public void addActivity(Activity a) {
		activityKeys.add(new Key<Activity>(Activity.class, a.getId()));
	}
	
	

}
